package com.wj.tool.common.exception;


import com.wj.tool.common.exception.message.ApplicationMessage;
import com.wj.tool.common.exception.message.MessageType;
import org.apache.commons.lang3.StringUtils;

public class SelfException extends BusinessException{

    public SelfException(String message) {
        super(SelfErrorMessage.failure(message));
    }

    public SelfException(int code, String message){
        super(SelfErrorMessage.failure(code, message));
    }

    static class SelfErrorMessage extends ApplicationMessage {
        public static final int NACOS_ERROR_CODE = 20201;
        public static final String NACOS_ERROR_CODE_20201_MESSAGE = " run failure ";

        public static SelfErrorMessage failure(String message) {
            return new SelfErrorMessage(NACOS_ERROR_CODE,
                    StringUtils.isEmpty(message) ? NACOS_ERROR_CODE_20201_MESSAGE : message , MessageType.BUSINESS);
        }

        public static SelfErrorMessage failure(int code, String message) {
            return new SelfErrorMessage(code,
                    StringUtils.isEmpty(message) ? NACOS_ERROR_CODE_20201_MESSAGE : message , MessageType.BUSINESS);
        }

        public SelfErrorMessage(int code, String message, MessageType type) {
            super(code, message, type);
        }
    }
}